# https://www.baidu.com/s?wd=%E5%91%A8%E6%9D%B0%E4%BC%A6
import urllib.request
import urllib.parse
# 需求：获取周杰伦的网页的源码
# url = 'https://www.baidu.com/s?wd=%E5%91%A8%E6%9D%B0%E4%BC%A'
url = 'https://www.baidu.com/s?wd='

# 请求对象的定制是防止反扒的第一手段
headers = {
    'user-agent:' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/134.0.0.0 Safari/537.36 Edg/134.0.0.0'
}

# 将周杰伦三个字变成unicode编码的格式
# urllib.parse
name = urllib.parse.quote('周杰伦')
url = url + name

# 请求对象的定制
request = urllib.request.Request(url=url,headers=headers)

# 模拟浏览器向服务器发送请求
response = urllib.request.urlopen(url)

# 获取响应的内容
content = response.read().decode('utf-8')

print(content)